package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.domain.MarketAdminExample;
import com.cskaoyan.market.db.mapper.MarketAdminMapper;
import com.cskaoyan.market.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

public class AdminAuthServiceImpl implements AdminAuthService {
    @Override
    public MarketAdmin login(String username, String password) {
        SqlSession sqlSession = MybatisUtils.getSession();
        MarketAdminMapper marketAdminMapper = sqlSession.getMapper(MarketAdminMapper.class);
        MarketAdminExample marketAdminExample = new MarketAdminExample();

        MarketAdminExample.Criteria criteria = marketAdminExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        //最终拼接出了 and password = #{password}
        criteria.andPasswordEqualTo(password);


        MarketAdmin admin = marketAdminMapper.selectOneByExample(marketAdminExample);

        sqlSession.close();
        return admin;
    }
}
